﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Coniometer.Model;
using Coniometer.Service;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;

namespace Coniometer.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        public List<NavigationMenu> NavigationMenuItems { get; }

        public DelegateCommand<ListBox> ItemSelectionChangedCommand { set; get; }
        public DelegateCommand LoginOutCommand { set; get; }

        public MainWindowViewModel(IRegionManager regionManager, IAppDataService dataService)
        {
            NavigationMenuItems = dataService.GetNavigationMenu();

            ItemSelectionChangedCommand = new DelegateCommand<ListBox>(listBox =>
            {
                var region = regionManager.Regions["ContentRegion"];
                switch (listBox.SelectedIndex)
                {
                    case 0:
                        region.RequestNavigate("SimplePage");
                        //通知页面刷新数据
                        break;
                    case 1:
                        region.RequestNavigate("DataPage");
                        //通知页面刷新数据
                        break;
                    case 2:
                        region.RequestNavigate("TaskPage");
                        //通知页面刷新数据
                        break;
                    case 3:
                        region.RequestNavigate("SettingPage");
                        break;
                }
            });

            LoginOutCommand = new DelegateCommand(delegate
            {
                var result = MessageBox.Show("是否退出登录？", "温馨提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
                if (result == MessageBoxResult.OK)
                {
                    Application.Current.Shutdown();
                }
            });
        }
    }
}